/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seso;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTable;

/**
 *
 * @author Administrator
 */
public class RTableScrollPane extends javax.swing.JScrollPane {

    private boolean isFirstTime = true;
    private Color tableBackgroundColor = new Color(235, 238, 241);
    private Color tableHeaderBGColor = new Color(114,158,191);
    private int imageHeight = Util.getUserImage("resources/TableHeaderLeftBackground.png").getHeight(null);
    
    RTableHeaderBackground rTableHeaderBackground;

    public RTableScrollPane() {
        super();
        
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(128, 128, 128)));

        setBackground(tableHeaderBGColor);
        getViewport().setBackground(tableBackgroundColor);
    }

    @Override
    protected void paintComponent(Graphics g) {

        if (java.beans.Beans.isDesignTime()) {
            super.paintComponent(g);
            return;
        }
        
        if (isFirstTime) {
            isFirstTime = false;
            rTableHeaderBackground = new RTableHeaderBackground();
            getParent().add(rTableHeaderBackground);
        }
        
        getViewport().getComponent(0).setBackground(tableBackgroundColor);

        int width = getWidth();
        int height = getHeight();
        
        Rectangle rect = new Rectangle(0, 1, width, height - 1);
        
        g.setClip(rect);
        
        if (rTableHeaderBackground != null) {
            rTableHeaderBackground.setBounds(getX(), getY() - 12 , width, imageHeight);
            rTableHeaderBackground.repaint();
        }
        
        super.paintComponent(g);
    }
}
